import java.util.HashMap;
import java.util.HashSet;

public class text190 {

    public static int lengthOfLongestSubstring (String s) {
        HashMap<Character,Integer> b=new HashMap<>();
        int[]arr=new int[s.length()];
        b.put(s.charAt(0),1);
        arr[0]=1;
        int max=0;
        int i=0;
        for(i=1;i<s.length();i++)
        {
            char ch=s.charAt(i);
            if(!b.containsKey(ch))
            {
                arr[i]=arr[i-1]+1;
                b.put(ch,1);
            }
            else
            {
                arr[i]=Math.min(arr[i-1]+1,i-b.get(ch));
                int a=b.get(ch);
                b.put(ch,a+1);
            }
            max=Math.max(max,arr[i]);

        }
        return max;


    }
    public static void main(String[] args) {
        String d="abcabcbb";
        int b=lengthOfLongestSubstring(d);
        System.out.println(b);

    }
}
